package org.mat.ipaas.ucenter.bff.admin.modules.system;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.mat.framework.lang.dto.MatApiResponse;
import org.mat.ipaas.ucenter.service.api.system.SysFilesRestAPI;
import org.mat.ipaas.ucenter.service.dto.system.entity.SysFilesDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 知识库-文档管理
 */
@Slf4j
@Api(tags = "知识库-文档管理")
@RestController
@RequestMapping("/sys/files")
public class SysFilesController {

    @Autowired
    private SysFilesRestAPI sysFilesRestAPI;

    /**
     * 分页列表查询
     *
     * @param sysFilesDTO
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @ApiOperation(value = "知识库-文档管理-分页列表查询", notes = "知识库-文档管理-分页列表查询")
    @GetMapping(value = "/list")
    public MatApiResponse<?> queryPageList(SysFilesDTO sysFilesDTO,
                                           @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                           @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                           HttpServletRequest req) {
        MatApiResponse<?> matApiResponse = sysFilesRestAPI.queryPageList(sysFilesDTO, pageNo, pageSize, req);
        return matApiResponse;
    }

    /**
     * 添加
     *
     * @param sysFilesDTO
     * @return
     */
    @ApiOperation(value = "知识库-文档管理-添加", notes = "知识库-文档管理-添加")
    @PostMapping(value = "/add")
    public MatApiResponse<?> add(@RequestBody SysFilesDTO sysFilesDTO) {
        MatApiResponse<?> matApiResponse = sysFilesRestAPI.add(sysFilesDTO);
        return matApiResponse;
    }

    /**
     * 编辑
     *
     * @param sysFilesDTO
     * @return
     */
    @ApiOperation(value = "知识库-文档管理-编辑", notes = "知识库-文档管理-编辑")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    public MatApiResponse<?> edit(@RequestBody SysFilesDTO sysFilesDTO) {
        MatApiResponse<?> matApiResponse = sysFilesRestAPI.edit(sysFilesDTO);
        return matApiResponse;
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "知识库-文档管理-通过id删除", notes = "知识库-文档管理-通过id删除")
    @DeleteMapping(value = "/delete")
    public MatApiResponse<?> delete(@RequestParam(name = "id", required = true) String id) {
        MatApiResponse<?> matApiResponse = sysFilesRestAPI.delete(id);
        return matApiResponse;
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @ApiOperation(value = "知识库-文档管理-批量删除", notes = "知识库-文档管理-批量删除")
    @DeleteMapping(value = "/deleteBatch")
    public MatApiResponse<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        MatApiResponse<?> matApiResponse = sysFilesRestAPI.deleteBatch(ids);
        return matApiResponse;
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "知识库-文档管理-通过id查询", notes = "知识库-文档管理-通过id查询")
    @GetMapping(value = "/queryById")
    public MatApiResponse<?> queryById(@RequestParam(name = "id", required = true) String id) {
        MatApiResponse<?> matApiResponse = sysFilesRestAPI.queryById(id);
        return matApiResponse;
    }

    /**
     * 导出excel
     *
     * @param sysFilesDTO
     */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(SysFilesDTO sysFilesDTO) {
        ModelAndView modelAndView = sysFilesRestAPI.exportXls(sysFilesDTO);
        return modelAndView;
    }

    /**
     * 通过excel导入数据
     *
     * @return
     */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public MatApiResponse<?> importExcel() {
        MatApiResponse<?> matApiResponse = sysFilesRestAPI.importExcel();
        return matApiResponse;
    }

}
